import { ElMessageBox } from 'element-plus'
import { DBUtil } from '@u/indexedDB'
const statiConfig = window.__config__ || {}

export default () => {
	const version = statiConfig.VERSION
	let localVersion = localStorage.getItem('version')
	// 存在版本
	if (version) {
		if (!localVersion) {
			localStorage.clear()
			localStorage.setItem('version', version)
			window.location.reload()
		} else {
			if (localVersion != version) {
				ElMessageBox.alert('系统检测到有新版本，即将更新？', '系统提示', {
					confirmButtonText: '确定',
					callback: () => {
						// 清空数据库
						new DBUtil().clear()
						// 清空缓存
						localStorage.clear()
						// 更新版本
						localStorage.setItem('version', version)
						window.location.reload()
					}
				})
			}
		}
	}
}
